$(function () {
    $.ajax({
        url:"/information/restuserorder",
        type:"type",
        data:"userid="+$("#userid"),
        dataType:"json",
        success:function (data) {
            //总数
            var pageinfo=0;
            //不会使用data获取key的集合
            for(var key in data){
                pageinfo++;
                $(".xianshi").append("<li class='uc-order-item uc-order-item uc-order-item-finish xianshi"+key+"'></li>");
                var keyname=key;
                if(key=="20020221"){
                    var i=0;
                    for (var information in data[key]){
                        if(i==0){
                            $(".xianshi"+key).append("<div class='order-remove J_removeBtn'> <img src='//i1.mifile.cn/f/i/2019/order/trash.png' alt='垃圾桶'></div><div class='order-detail ceshi'>" +
                                "<div class='order-summary'><div class='order-status'> 已收货 </div></div><table class='order-detail-table'><thead><tr><th class='col-main'>" +
                                "<p class='caption-info'>"+data[key][i].datetime+"<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                "<a href=''>"+data[key][i].ordernumber+"</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th>" +
                                "<th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>"+data[key][i].pricez+"</span>元</p></th></tr></thead>" +
                                "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                "<img src='../img/"+data[key][i].img+"' width='80' height='80' alt='"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"'></a></div>" +
                                "<p class='name'><a href='' target='_blank'>"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"</a></p>" +
                                "<p class='price'>"+data[key][i].pricez+"元 × "+data[key][i].number+"</p></li></ul></td><td class='order-actions'><a class='btn btn-small btn-line-gray' href=''>订单详情</a>" +
                                "<a class='btn btn-small btn-line-gray comments' href=''>评价晒单</a><a class='btn btn-small btn-line-gray' href=''>申请售后</a>" +
                                "<a href='' class='btn btn-small btn-line-gray btn-contract'>联系客服</a></td></tr></tbody></table>");
                            i++;
                        }else{
                            $(".ceshi").append("<div class='order-detail' style='border-top: 1px solid #b0b0b0;'><div class='order-summary'><div class='order-status'> 已收货 <span class='tag tag-package'>包裹3</span> </div></div>" +
                                "<table class='order-detail-table'><thead><tr><th class='col-main'><p class='caption-info'>"+data[key][i].datetime+"<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                "<a href=''>"+data[key][i].ordernumber+"</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th><th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>"+data[key][i].pricez+"</span>元</p></th></tr></thead>" +
                                "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                "<img src='../img/"+data[key][i].img+"' width='80' height='80' alt='"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"'></a></div>" +
                                "<p class='name'><a href='' target='_blank'>"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"</a></p>" +
                                "<p class='price'>"+data[key][i].pricez+"元 × "+data[key][i].number+"</p></li></ul></td><td class='order-actions'></td></tr></tbody></table></div>");
                            i++;
                        }
                    }
                }else if(key=="20020222"){

                    var i=0;
                    if(i==0){
                        $(".xianshi"+key).append("<div class='order-remove J_removeBtn'> <img src='//i1.mifile.cn/f/i/2019/order/trash.png' alt='垃圾桶'></div><div class='order-detail ceshi'>" +
                            "<div class='order-summary'><div class='order-status'> 已收货 </div></div><table class='order-detail-table'><thead><tr><th class='col-main'>" +
                            "<p class='caption-info'>"+data[key][i].datetime+"<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                            "<a href=''>"+data[key][i].ordernumber+"</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th>" +
                            "<th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>"+data[key][i].pricez+"</span>元</p></th></tr></thead>" +
                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                            "<img src='../img/"+data[key][i].img+"' width='80' height='80' alt='"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"'></a></div>" +
                            "<p class='name'><a href='' target='_blank'>"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"</a></p>" +
                            "<p class='price'>"+data[key][i].pricez+"元 × "+data[key][i].number+"</p></li></ul></td><td class='order-actions'><a class='btn btn-small btn-line-gray' href=''>订单详情</a>" +
                            "<a class='btn btn-small btn-line-gray comments' href=''>评价晒单</a><a class='btn btn-small btn-line-gray' href=''>申请售后</a>" +
                            "<a href='' class='btn btn-small btn-line-gray btn-contract'>联系客服</a></td></tr></tbody></table>");
                        i++;
                    }else{
                        $(".ceshi").append("<div class='order-detail' style='border-top: 1px solid #b0b0b0;'><div class='order-summary'><div class='order-status'> 已收货 <span class='tag tag-package'>包裹3</span> </div></div>" +
                            "<table class='order-detail-table'><thead><tr><th class='col-main'><p class='caption-info'>"+data[key][i].datetime+"<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                            "<a href=''>"+data[key][i].ordernumber+"</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th><th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>"+data[key][i].pricez+"</span>元</p></th></tr></thead>" +
                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                            "<img src='../img/"+data[key][i].img+"' width='80' height='80' alt='"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"'></a></div>" +
                            "<p class='name'><a href='' target='_blank'>"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"</a></p>" +
                            "<p class='price'>"+data[key][i].pricez+"元 × "+data[key][i].number+"</p></li></ul></td><td class='order-actions'></td></tr></tbody></table></div>");
                        i++;
                    }
                }else if(key=="20020223"){

                    var i=0;
                    if(i==0){
                        $(".xianshi"+key).append("<div class='order-remove J_removeBtn'> <img src='//i1.mifile.cn/f/i/2019/order/trash.png' alt='垃圾桶'></div><div class='order-detail ceshi'>" +
                            "<div class='order-summary'><div class='order-status'> 已收货 </div></div><table class='order-detail-table'><thead><tr><th class='col-main'>" +
                            "<p class='caption-info'>"+data[key][i].datetime+"<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                            "<a href=''>"+data[key][i].ordernumber+"</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th>" +
                            "<th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>"+data[key][i].pricez+"</span>元</p></th></tr></thead>" +
                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                            "<img src='../img/"+data[key][i].img+"' width='80' height='80' alt='"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"'></a></div>" +
                            "<p class='name'><a href='' target='_blank'>"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"</a></p>" +
                            "<p class='price'>"+data[key][i].pricez+"元 × "+data[key][i].number+"</p></li></ul></td><td class='order-actions'><a class='btn btn-small btn-line-gray' href=''>订单详情</a>" +
                            "<a class='btn btn-small btn-line-gray comments' href=''>评价晒单</a><a class='btn btn-small btn-line-gray' href=''>申请售后</a>" +
                            "<a href='' class='btn btn-small btn-line-gray btn-contract'>联系客服</a></td></tr></tbody></table>");
                        i++;
                    }else{
                        $(".ceshi").append("<div class='order-detail' style='border-top: 1px solid #b0b0b0;'><div class='order-summary'><div class='order-status'> 已收货 <span class='tag tag-package'>包裹3</span> </div></div>" +
                            "<table class='order-detail-table'><thead><tr><th class='col-main'><p class='caption-info'>"+data[key][i].datetime+"<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                            "<a href=''>"+data[key][i].ordernumber+"</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th><th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>"+data[key][i].pricez+"</span>元</p></th></tr></thead>" +
                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                            "<img src='../img/"+data[key][i].img+"' width='80' height='80' alt='"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"'></a></div>" +
                            "<p class='name'><a href='' target='_blank'>"+data[key][i].name+data[key][i].versiontype+data[key][i].colorname+"</a></p>" +
                            "<p class='price'>"+data[key][i].pricez+"元 × "+data[key][i].number+"</p></li></ul></td><td class='order-actions'></td></tr></tbody></table></div>");
                        i++;
                    }
                }
        }
            var totalpage = pageinfo / 3;
            //总页数
            var yushu = pageinfo % 3;

            if(yushu>0){
                totalpage+=1;
            }
            var pagespan=document.createElement('span');
            for (var i = 1;i <= totalpage;i++){
                var a = document.createElement('a');
                a.innerText = i;
                a.style.margin=5;
                a.className = 'yeshu';
                pagespan.append(a);
            }
            if(totalpage > 1){
                var ce = document.createElement("div");
                $(".fenye").append("<a style='margin: 0px 5px' class='yeshu'>首页</a>");
                $(".fenye").append(pagespan);
                $(".fenye").append("<a style='margin: 0px 5px' class='yeshu'>末页</a>");
            }

            totalpage=Math.floor(totalpage);
            $(".yeshu").click(function () {
                var that = $(this);
                var realpageno = 0;
                if(that.text()=="首页"){
                    realpageno=1;
                }else if(that.text()=="末页"){
                    realpageno=totalpage;
                }else{
                    realpageno=that.text();
                }
                $(".xianshi").html("");
                    $.ajax({
                        url:"/information/restuserorder?realpageno="+realpageno,
                        type:"type",
                        data:"",
                        dataType:"json",
                        success:function (data) {
                            var ke = 0;
                            for(var key in data) {
                                $(".xianshi").append("<li class='uc-order-item uc-order-item uc-order-item-finish xianshi" + key + "'></li>");
                                var keyname = key;
                                ke = realpageno * 3;
                                if (key == "2002022"+(ke-2)) {
                                    var i = 0;
                                    for (var information in data[key]) {
                                        if (i == 0) {
                                            $(".xianshi2002022"+(ke-2)).append("<div class='order-remove J_removeBtn'> <img src='//i1.mifile.cn/f/i/2019/order/trash.png' alt='垃圾桶'></div><div class='order-detail ceshi'>" +
                                                "<div class='order-summary'><div class='order-status'> 已收货 </div></div><table class='order-detail-table'><thead><tr><th class='col-main'>" +
                                                "<p class='caption-info'>" + data[key][i].datetime + "<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                                "<a href=''>" + data[key][i].ordernumber + "</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th>" +
                                                "<th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>" + data[key][i].pricez + "</span>元</p></th></tr></thead>" +
                                                "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                                "<img src='../img/" + data[key][i].img + "' width='80' height='80' alt='" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "'></a></div>" +
                                                "<p class='name'><a href='' target='_blank'>" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "</a></p>" +
                                                "<p class='price'>" + data[key][i].pricez + "元 × " + data[key][i].number + "</p></li></ul></td><td class='order-actions'><a class='btn btn-small btn-line-gray' href=''>订单详情</a>" +
                                                "<a class='btn btn-small btn-line-gray comments' href=''>评价晒单</a><a class='btn btn-small btn-line-gray' href=''>申请售后</a>" +
                                                "<a href='' class='btn btn-small btn-line-gray btn-contract'>联系客服</a></td></tr></tbody></table>");
                                            i++;
                                        } else {
                                            $(".ceshi").append("<div class='order-detail' style='border-top: 1px solid #b0b0b0;'><div class='order-summary'><div class='order-status'> 已收货 <span class='tag tag-package'>包裹3</span> </div></div>" +
                                                "<table class='order-detail-table'><thead><tr><th class='col-main'><p class='caption-info'>" + data[key][i].datetime + "<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                                "<a href=''>" + data[key][i].ordernumber + "</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th><th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>" + data[key][i].pricez + "</span>元</p></th></tr></thead>" +
                                                "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                                "<img src='../img/" + data[key][i].img + "' width='80' height='80' alt='" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "'></a></div>" +
                                                "<p class='name'><a href='' target='_blank'>" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "</a></p>" +
                                                "<p class='price'>" + data[key][i].pricez + "元 × " + data[key][i].number + "</p></li></ul></td><td class='order-actions'></td></tr></tbody></table></div>");
                                            i++;
                                        }
                                    }
                                } else if (key == "2002022"+(ke-1)) {

                                    var i = 0;
                                    if (i == 0) {
                                        $(".xianshi2002022"+(ke-1)).append("<div class='order-remove J_removeBtn'> <img src='//i1.mifile.cn/f/i/2019/order/trash.png' alt='垃圾桶'></div><div class='order-detail ceshi'>" +
                                            "<div class='order-summary'><div class='order-status'> 已收货 </div></div><table class='order-detail-table'><thead><tr><th class='col-main'>" +
                                            "<p class='caption-info'>" + data[key][i].datetime + "<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                            "<a href=''>" + data[key][i].ordernumber + "</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th>" +
                                            "<th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>" + data[key][i].pricez + "</span>元</p></th></tr></thead>" +
                                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                            "<img src='../img/" + data[key][i].img + "' width='80' height='80' alt='" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "'></a></div>" +
                                            "<p class='name'><a href='' target='_blank'>" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "</a></p>" +
                                            "<p class='price'>" + data[key][i].pricez + "元 × " + data[key][i].number + "</p></li></ul></td><td class='order-actions'><a class='btn btn-small btn-line-gray' href=''>订单详情</a>" +
                                            "<a class='btn btn-small btn-line-gray comments' href=''>评价晒单</a><a class='btn btn-small btn-line-gray' href=''>申请售后</a>" +
                                            "<a href='' class='btn btn-small btn-line-gray btn-contract'>联系客服</a></td></tr></tbody></table>");
                                        i++;
                                    } else {
                                        $(".ceshi").append("<div class='order-detail' style='border-top: 1px solid #b0b0b0;'><div class='order-summary'><div class='order-status'> 已收货 <span class='tag tag-package'>包裹3</span> </div></div>" +
                                            "<table class='order-detail-table'><thead><tr><th class='col-main'><p class='caption-info'>" + data[key][i].datetime + "<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                            "<a href=''>" + data[key][i].ordernumber + "</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th><th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>" + data[key][i].pricez + "</span>元</p></th></tr></thead>" +
                                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                            "<img src='../img/" + data[key][i].img + "' width='80' height='80' alt='" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "'></a></div>" +
                                            "<p class='name'><a href='' target='_blank'>" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "</a></p>" +
                                            "<p class='price'>" + data[key][i].pricez + "元 × " + data[key][i].number + "</p></li></ul></td><td class='order-actions'></td></tr></tbody></table></div>");
                                        i++;
                                    }
                                } else if (key == "2002022"+ke) {

                                    var i = 0;
                                    if (i == 0) {
                                        $(".xianshi2002022"+ke).append("<div class='order-remove J_removeBtn'> <img src='//i1.mifile.cn/f/i/2019/order/trash.png' alt='垃圾桶'></div><div class='order-detail ceshi'>" +
                                            "<div class='order-summary'><div class='order-status'> 已收货 </div></div><table class='order-detail-table'><thead><tr><th class='col-main'>" +
                                            "<p class='caption-info'>" + data[key][i].datetime + "<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                            "<a href=''>" + data[key][i].ordernumber + "</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th>" +
                                            "<th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>" + data[key][i].pricez + "</span>元</p></th></tr></thead>" +
                                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                            "<img src='../img/" + data[key][i].img + "' width='80' height='80' alt='" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "'></a></div>" +
                                            "<p class='name'><a href='' target='_blank'>" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "</a></p>" +
                                            "<p class='price'>" + data[key][i].pricez + "元 × " + data[key][i].number + "</p></li></ul></td><td class='order-actions'><a class='btn btn-small btn-line-gray' href=''>订单详情</a>" +
                                            "<a class='btn btn-small btn-line-gray comments' href=''>评价晒单</a><a class='btn btn-small btn-line-gray' href=''>申请售后</a>" +
                                            "<a href='' class='btn btn-small btn-line-gray btn-contract'>联系客服</a></td></tr></tbody></table>");
                                        i++;
                                    } else {
                                        $(".ceshi").append("<div class='order-detail' style='border-top: 1px solid #b0b0b0;'><div class='order-summary'><div class='order-status'> 已收货 <span class='tag tag-package'>包裹3</span> </div></div>" +
                                            "<table class='order-detail-table'><thead><tr><th class='col-main'><p class='caption-info'>" + data[key][i].datetime + "<span class='sep'>|</span>席亚博<span class='sep'>|</span>订单号：" +
                                            "<a href=''>" + data[key][i].ordernumber + "</a><span class='sep'>|</span>在线支付（支付宝快捷支付）</p></th><th class='col-sub'><p class='caption-price'>实付金额：<span class='num'>" + data[key][i].pricez + "</span>元</p></th></tr></thead>" +
                                            "<tbody><tr><td class='order-items'><ul class='goods-list'><li><div class='figure figure-thumb'><a href='' target='_blank'>" +
                                            "<img src='../img/" + data[key][i].img + "' width='80' height='80' alt='" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "'></a></div>" +
                                            "<p class='name'><a href='' target='_blank'>" + data[key][i].name + data[key][i].versiontype + data[key][i].colorname + "</a></p>" +
                                            "<p class='price'>" + data[key][i].pricez + "元 × " + data[key][i].number + "</p></li></ul></td><td class='order-actions'></td></tr></tbody></table></div>");
                                        i++;
                                    }
                                }
                            }
                        },
                        error:function (e) {
                            alert("获取失败");
                        }
                    })
            })

        },
        error:function (e) {
            alert("获取失败");
        }
    })
})
